from django.db import models


# Create your models here.
class User(models.Model):
    # 主键  通过参数声明主键
    id = models.AutoField(primary_key=True)
    # 用户名  字符串类型需要声明长度限制
    username = models.CharField(max_length=200)
    # 密码
    password = models.CharField(max_length=255)
    # 头像
    # image = models.CharField(max_length=200)
    image = models.ImageField(upload_to='static/upload/')
    # 类别 0代表学生 1代表老师
    type = models.IntegerField()
    #页面请求统计
    num = models.IntegerField(default=0)

    # 声明表名
    class Meta:
        # 必须和数据库中的表名吻合
        db_table = "user"


# 课程分类
class Category(models.Model):
    # 主键  通过参数声明主键
    id = models.AutoField(primary_key=True)
    # 分类名称
    name = models.CharField(max_length=200)

    # 声明表名
    class Meta:
        # 必须和数据库中的表名吻合
        db_table = "category"


# 课程表
class Course(models.Model):
    # 主键  通过参数声明主键
    id = models.AutoField(primary_key=True)
    # 用户名  字符串类型需要声明长度限制
    title = models.CharField(max_length=200)
    # 课程内容
    desc = models.CharField(max_length=500)
    # 图片
    img = models.ImageField(upload_to='static/upload/')
    # 价格
    price = models.IntegerField()
    # 类别
    cid = models.IntegerField()
    # 用户id
    uid = models.IntegerField()
    # 关注数
    flow = models.IntegerField(default=0, null=True)

    # 声明表名
    class Meta:
        # 必须和数据库中的表名吻合
        db_table = "course"


# 平论表
class Comment(models.Model):
    # 主键  通过参数声明主键
    id = models.AutoField(primary_key=True)
    # 用户名  字符串类型需要声明长度限制
    content = models.CharField(max_length=500)
    # 课程id
    cid = models.IntegerField()

    # 声明表名
    class Meta:
        # 必须和数据库中的表名吻合
        db_table = "comment"


# 关注表
class Flows(models.Model):
     # 主键  通过参数声明主键
    id = models.AutoField(primary_key=True)
    # 用户id
    uid = models.IntegerField()
    # 课程id
    cid = models.IntegerField()

    class Meta:
        db_table = "flows"


# 优惠卷
class Codes(models.Model):
       # 主键  通过参数声明主键
    id = models.AutoField(primary_key=True)
    # 随机码
    code = models.CharField(max_length=500)
    # 折扣
    discount = models.FloatField()
    # 是否过期
    status = models.IntegerField(default=1)
    class Meta:
        db_table = "codes"


# 订单表
class Orders(models.Model):
       # 主键  通过参数声明主键
    id = models.AutoField(primary_key=True)
    # 订单id
    orderid = models.CharField(max_length=500)
    # 用户id
    uid = models.IntegerField()
    # 价格
    price = models.IntegerField()
    # 支付状态
    status = models.IntegerField(default=1)
    # 课程明细
    cids = models.CharField(max_length=500)
    
    class Meta:
        db_table = "orders"
